package jdbc;

import java.sql.*;

/**
 * @author oldliu
 * @since 1.0
 * 增加新课
 */
public class AddNewSubject {
    public static void main(String[] args) {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
            return;
        }
        //          固定：类型://ip+端口/数据库名?其他参数
        String url = "jdbc:mysql://localhost:3308/java82";
        Connection conn = null;
        Statement st = null;

        try {
            conn = DriverManager.getConnection(url, "root", "root1234");
            st = conn.createStatement();
            int rows = st.executeUpdate("insert into s_subject(subjectname,classhour,gradeid)values('氢弹回收',100,7)");
            System.out.println("成功增加了:"+rows+"行");

        } catch (SQLException e) {
            e.printStackTrace();
        } finally {

            try {
                if (st != null)
                    st.close();


            } catch (SQLException e) {
                e.printStackTrace();
            }
            try {
                if (conn != null)
                    conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}
